﻿#if NET35

//为接口统一,定义与 netstandard2.0环境下Microsoft.Extensions.DependencyInjection.IServiceCollection 相同的接口及操作    
using System;
namespace Kernelx.Common.DependencyInjection
{
    /// <summary>
    /// 
    /// </summary>
    public enum ServiceLifetime
    {
        /// <summary>
        /// 单例
        /// </summary>
        Singleton,

        /// <summary>
        /// 范围内
        /// </summary>
        Scoped,

        /// <summary>
        /// 瞬时
        /// </summary>
        Transient
    }

    /// <summary>
    /// 
    /// </summary>
    public class ServiceDescriptor
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="implementationType"></param>
        /// <param name="lifetime"></param>
        public ServiceDescriptor(Type serviceType, Type implementationType, ServiceLifetime lifetime)
        {
            ServiceType = serviceType;
            ImplementationType = implementationType;
            Lifetime = lifetime;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="factory"></param>
        /// <param name="lifetime"></param>
        public ServiceDescriptor(Type serviceType, Func<IServiceProvider, object> factory, ServiceLifetime lifetime)
        {
            ServiceType = serviceType;
            ImplementationFactory = factory;
            Lifetime = lifetime;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="instance"></param>
        public ServiceDescriptor(Type serviceType, object instance)
        {
            ServiceType = serviceType;
            ImplementationInstance = instance;
            Lifetime = ServiceLifetime.Singleton;
        }


        /// <summary>
        /// 
        /// </summary>
        public ServiceLifetime Lifetime { get; private set; }

        /// <summary>
        /// 
        /// </summary>
        public Type ServiceType { get; private set; }

        /// <summary>
        /// 
        /// </summary>
        public Type ImplementationType { get; private set; }

        /// <summary>
        /// 
        /// </summary>
        public object ImplementationInstance { get; private set; }

        /// <summary>
        /// 
        /// </summary>
        public Func<IServiceProvider, object> ImplementationFactory { get; private set; }
    }
}

#endif